package com.aikon.wht.matcher;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class TestOfMatcher {

    public void mmm(String rgx, String input) {
        Pattern pattern = Pattern.compile(rgx);
        Matcher matcher = pattern.matcher(input);
        print(matcher.matches());

    }

    public void nnn() {
        Pattern namePattern = Pattern.compile("\\{([^/]+?)\\}");
        String s = "{11}{22}{33}{44}{55}";
        Matcher matcher = namePattern.matcher(s);
//        System.out.println(matcher.find());
//        int start = matcher.start();
//        int end = matcher.end();
//        System.out.println(start);
//        System.out.println(end);
//        String ss = s.substring(start, end);
//        System.out.println(ss);
//        System.out.println(Pattern.quote(ss));
        System.out.println("xxxxxxxxxxxxxxxxxxxxx");
        for (int e = 0; matcher.find();e=matcher.end()) {
//            System.out.println(matcher.start());
            System.out.println(e);
            System.out.println(matcher.start());
            System.out.println(matcher.group(1));
//            System.out.println(matcher.start());
        }
    }

    private static void print(Object find) {

        System.out.println(find.toString());
    }

    public static void main(String[] args) {
        TestOfMatcher testOfMatcher = new TestOfMatcher();
        testOfMatcher.nnn();
        testOfMatcher.mmm("[0-9]{2}:[0-9]{2}:[0-9]{2}", "12:12:12");
        // print("\n");
        // testOfMatcher.mmm("(3\\s{1,10}2\\s{1,10})|(5\\s)", "3 2 ");
        // testOfMatcher.mmm("(3\\s{1,10}2\\s{1,10})|(5\\s)", "5 ");
        // System.out.println(String.valueOf( new BigDecimal( new Long(75)
        // *1.0/100)));
        // DecimalFormat d1 =new DecimalFormat("0.0");
        // String string = "I work here.I work here.I work here.I work here.I
        // work here.I work here.I work here.I work here.I work here.I work
        // here.";
        // Pattern pattern = Pattern.compile("[.]+");
        // String[] strings = pattern.split(string);
        //
        // for (String string2 : strings) {
        // System.out.println(string2);
        // }
        // System.out.println( d1.format( new Double( 100)/100));
        //
        // Pattern pattern1 = Pattern.compile("\\s");
        // String[] strings1 = pattern1.split(string);
        // for (String string2 : strings1) {
        // print(string2);
        // }
        //
        // Pattern p = Pattern.compile("Kelvin");
        // // 用Pattern类的matcher()方法生成一个Matcher对象
        // Matcher m = p.matcher("Kelvin Li and Kelvin Chan are both working in
        // Kelvin Chen's KelvinSoftShop company");
        // StringBuffer sb = new StringBuffer();
        // m.find();
        // m.appendReplacement(sb, "!!");
        // m.appendTail(sb);
        // print(sb);
        //
        // int i = 0;
        // // 使用find()方法查找第一个匹配的对象
        // boolean result = m.find();
        // // 使用循环将句子里所有的kelvin找出并替换再将内容加到sb里
        // while (result) {
        // i++;
        // m.appendReplacement(sb, "dd");
        // System.out.println("第" + i + "次匹配后sb的内容是：" + sb);
        // // 继续查找下一个匹配对象
        // result = m.find();
        // }
        // // 最后调用appendTail()方法将最后一次匹配后的剩余字符串加到sb里；
        // m.appendTail(sb);
        // System.out.println("调用m.appendTail(sb)后sb的最终内容是:" + sb.toString());
        //
        // m = p.matcher("Kelvin Li and Kelvin Chan are both working in Kelvin
        // Chen's KelvinSoftShop company");
        //
        // print(m.replaceAll("xx"));
        // m = p.matcher("Kelvin Li and Kelvin Chan are both working in Kelvin
        // Chen's KelvinSoftShop company");
        // List<Integer> integers = Lists.newArrayList(1,2,3,4,5,6,7,8,9,0);
        // List<Integer> ingers = Lists.newArrayList(1,2,3,4,16,17,5,6,7,8,9,0);
        // integers.removeAll(ingers);
        // System.out.println(integers.toArray().toString());

        String s = "34.00";
        String t = "56.50";
        String u = "98.00";

        System.out.println(longToCurrencyStringNoEndZero(100000L));
        System.out.println(longToCurrencyStringNoEndZero(4589L));

    }

    public static String longToCurrencyString(Long org) {
        if (org == null) {
            return "";
        }
        BigDecimal b = new BigDecimal(org * 1.0 / 100);
        DecimalFormat d1 = new DecimalFormat("#,##0.00");
        return d1.format(b);
    }

    public static String longToCurrencyStringNoEndZero(Long org) {
        String s = longToCurrencyString(org);
        s = s.replaceAll("0+?$", "");
        s = s.replaceAll("[.]$", "");
        return s;
    }
}
